package bairui.international.weixin.portal.miniapp.controller.user;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;

import bairui.international.model.domain.jpa.TB_User;
import bairui.international.service.Service_ProxyAreaAddress;
import bairui.international.service.Service_User;
import bairui.international.weixin.portal.miniapp.controller.user.C_User_Proxy_Page.OutputProduct;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 *
 * 代理
 *
 * @generated
 * 
 * @see STest_C_User_Proxy_Address 测试
 *
 */
@Controller
public class C_User_Proxy_Address
 extends SC_User_Proxy_Address 
{
	
	@Autowired private Service_ProxyAreaAddress service_ProxyAreaAddress;
	@Autowired private Service_User service_User;
	
	/**
	 * 编辑地址
	 */
	@Action(Address.class)
	@PostMapping(Address.RequestMappingValue)
	public @FomatOutput @ResponseBody Object address(
		ModelMap map, HttpServletRequest request,
		@RequestBody Input input,
		@RequestParam String skey
	) throws Exception {
		TB_User user = service_User.findOne(it->it.skey.eq(skey));
		service_ProxyAreaAddress.editAddress(
				user,
				input.getTownId(),
				input.getUsername(),
				input.getPhone(),
				input.getAddress()
			);
		//
		return null;
	}
	
	@AllArgsConstructor
	public static class Input {
		private @Getter Long townId;
		private @Getter String address;
		private @Getter String phone;
		private @Getter String username;
		private @Getter OutputProduct product;
	}
	

}
